package com.edu.boot.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.boot.entity.RecuritType;
import com.edu.boot.service.RecuritTypeService;
import com.edu.boot.mapper.RecuritTypeMapper;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
* @author Janson
* @description 针对表【recurit_type(职位类型表)】的数据库操作Service实现
* @createDate 2025-04-04 19:59:30
*/
@Service
public class RecuritTypeServiceImpl extends ServiceImpl<RecuritTypeMapper, RecuritType>
implements RecuritTypeService{
    @Override
    public RecuritType getRecuritTypeById(Long id) {
        RecuritType recuritType = this.getById(id);
        return recuritType;
    }
    @Override
    public boolean addRecuritType(RecuritType recuritType) {
        boolean save = this.save(recuritType);
        return save;
    }
    @Override
    public boolean updateRecuritType(RecuritType recuritType) {
        boolean update = this.updateById(recuritType);
        return update;
    }
    @Override
    public boolean deleteRecuritType(Long id) {
        boolean remove = this.removeById(id);
        return remove;
    }
        /**
     * 获取所有职位类型列表
     * @return 职位类型列表
     */
    @Override
    public List<RecuritType> getRecuritTypeList() {
        try {
            return this.list();
        } catch (Exception e) {
            // 记录日志或抛出自定义异常
            e.printStackTrace();
            return Collections.emptyList();
        }
    }
    
    @Override
    public Map<Integer, String> getRecuritTypeMap() {
        List<RecuritType> list = this.list();
        Map<Integer, String> collect = new HashMap<>();
        if (CollectionUtil.isNotEmpty(list)){
            collect = list.stream()
                    .collect(Collectors.toMap(RecuritType::getValue, RecuritType::getLabel));
        }
        return collect;
    }
    
    
}
